﻿define('viewModels/tasklist', ['system', 'viewModel', 'data/tasks', 'logger'], function (system, viewModel, data, logger) {

    function view() {
        var self = this;
        self.tasks = ko.observableArray([]);
        self.isLoading = ko.observable(false);
        self.activate = function (params, bind) {
            bind();
            self.isLoading(true);
            data.list(function(error, result) {
                self.isLoading(false);
                if (error) {
                    logger.error(error, true);
                } else {
                    self.tasks.removeAll();
                    $.each(result, function() {
                        self.tasks.push(new data.ListTask(this));
                    });
                }
               
            }, self);
        };

        self.taskDetails = function() {
            alert("ok");
        };
    }

    return new view();
});